package my.avoskagae.client.view.gwt;

import my.avoskagae.client.presenter.IMainPresenter;
import my.avoskagae.client.view.IMainView;
import my.avoskagae.utils.UserInfo;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.mvp4g.client.view.ReverseViewInterface;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Anchor;

public class MainView extends Composite implements IMainView, ReverseViewInterface<IMainPresenter> {

	private static MainViewUiBinder uiBinder = GWT.create(MainViewUiBinder.class);
	private IMainPresenter presenter;
	
	@Override
	public void setPresenter(IMainPresenter presenter) {
		this.presenter= presenter;		
	}

	@Override
	public IMainPresenter getPresenter() {
		return this.presenter;
	}
	
	interface MainViewUiBinder extends UiBinder<Widget, MainView> {
	}

	public MainView() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	@UiField
	Button button;
	//Переименовать в ...Widget
	@UiField FlowPanel mainList;
	@UiField FlowPanel detail;
	@UiField Label userNickname;
	@UiField Anchor logInLink;
	@UiField Anchor logOutLink;
	
	@UiHandler("button")
	void onClick(ClickEvent e) {
		Window.alert("Каталог покажись!");
		presenter.refresh();
	}

	@Override
	public void setMainList(IsWidget mainList) {
		this.mainList.clear();
		this.mainList.add(mainList);
	}

	@Override
	public void setDetail(IsWidget mainList) {
		this.detail.clear();
		this.detail.add(mainList);
	}

	@Override
	public void setUserNickname(String userNickname) {
		this.userNickname.setText("Hello, "+userNickname);
	}

	@Override
	public void setUserInfo(UserInfo userInfo) {
		userNickname.setText("Hello, "+userInfo.getNickname());
		logInLink.setHref(userInfo.getLogInLink());
		logOutLink.setHref(userInfo.getLogOutLink());
//		logInLink.setText(userInfo.getLogInLink(), );
	}

}
